//package com.hs.room.paging_source
//
//import androidx.paging.PagingSource
//import androidx.paging.PagingState
//import com.hs.room.model.sys.SysLog
//import com.hs.room.repository.SysLogRepository
//import kotlinx.coroutines.Dispatchers
//import kotlinx.coroutines.flow.collect
//import kotlinx.coroutines.withContext
//import javax.inject.Inject
//
//class SysLogPagingSource  constructor(private val sysLogRepository: SysLogRepository): PagingSource<Int, SysLog>() {
//
//    override fun getRefreshKey(state: PagingState<Int, SysLog>): Int? {
//        return state.anchorPosition?.let { anchorPosition ->
//            state.closestPageToPosition(anchorPosition)?.prevKey?.plus(1)
//                ?: state.closestPageToPosition(anchorPosition)?.nextKey?.minus(1)
//        }
//    }
//
//    override suspend fun load(params: LoadParams<Int>): LoadResult<Int, SysLog> {
//        try {
//            val pageIndex = params.key?: 1
//            val pageSize = params.loadSize
//            //1 0- 10 //2 10-20
//            val sysLogs =  sysLogRepository.getByCombinedConditions((pageIndex - 1) * pageSize,pageIndex * pageSize)
//            val nextKey = if (sysLogs.isEmpty()) {
//                null
//            } else {
//                pageIndex + 1
//            }
//            return LoadResult.Page(sysLogs,
//                prevKey = if (pageIndex == 0) null else pageIndex - 1,
//                nextKey = nextKey)
//        }catch (e:Exception){
//            e.printStackTrace()
//            return LoadResult.Error(e)
//        }
//    }
//}